package com.utils;

import android.os.Looper;


public abstract class TIME
{
	
	 private long start ;
//	public TIME(){
//		
//	}
	
/*	 
public	synchronized float get_elapsed_time(){  // 临界该函数
//	Looper.prepare();
	start = System.currentTimeMillis();   // 怎么Looper.loop()异常
	
	fuc();
	
		long current = System.currentTimeMillis();
		
		float t = (current - start) / 1000; 
		
		System.out.println(t+"s");
		
		return t;
	}
	
*/
	 
	 
	 
	 public	synchronized float get_elapsed_time(){  // 临界该函数
//			Looper.prepare();
			start = System.nanoTime();   // 怎么Looper.loop()异常
			
			fuc();  
			
				long current = System.nanoTime();
				
				float t = (current - start) / 1000000; //转换为毫秒
				
				System.out.println(t+"ms");
				
				return t;
			}
	 
	 
	 private long start_thread ;
	 public synchronized void get_elapsed_time_Thead(){
		 	
		 new Thread(){
			 @Override
			public void run() {
				// TODO Auto-generated method stub
				super.run();
				
				start_thread = System.nanoTime(); 
				 
				fuc();  
				
				float t = (System.nanoTime() - start_thread) / 1000000; 
				
				System.out.println(t+"ms");
				
			}
		 }.start();
		 	
	 }
	 
	 
	 
	 
	 /**
	  * 
	  * @param elapsed
	  * @param ms
	  */
	 public void time_to_go(final float ms){
		 
			final cHighTimer HighTimer = new cHighTimer();
			HighTimer.start_counter();
			
		 new Thread(){
			 
			 private float total_time ;
			 
			 @Override
			public void run() {
				// TODO Auto-generated method stub
				super.run();

				// 空转等待
				for(;;){
					float elapsed =HighTimer.get_elapsed_time();
					
					total_time +=elapsed;
					if(total_time > ms)
						break;
				}
				
				fuc();
				
				
			}
		 }.start();
		 
	 }
	 

	public abstract void fuc();
	
	

}

